//
//  NSDictionary+GRJDictionary.m
//  GRJTolCayFrwk
//
//  Created by apple on 2017/3/1.
//  Copyright © 2017年 Global Barter. All rights reserved.
//

#import "NSDictionary+GRJDictionary.h"

@implementation NSDictionary (GRJDictionary)
// __NSCFBoolean:私有类
// 私有API:苹果底层有这个类,但是没有暴露给我们用
// isKindOfClass:判断下是否是当前类或者子类


- (void)createPropertyCode
{
    // 根据字典中的key去生成对应属性
    // 模型中属性名 就是 key
    NSMutableString *codes = [NSMutableString string];
    
    // 遍历字典
    [self enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull key, id  _Nonnull value, BOOL * _Nonnull stop) {
        NSString *code;
        // 生成一行属性代码
        if ([value isKindOfClass:[NSString class]]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSString *%@;",key];
        } else if ([value isKindOfClass:[NSArray class]]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSArray *%@;",key];
        } else if ([value isKindOfClass:[NSDictionary class]]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@;",key];
        } else if ([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;",key];
        } else if ([value isKindOfClass:[NSNumber class]]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, assign) int %@;",key];
            
        }
        
        // 拼接属性代码
        [codes appendFormat:@"\n%@\n",code];
        
    }];
    
    NSLog(@"%@",codes);
    
    
}


@end
